package com.ruoyi.play.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.play.domain.WhereToGoOption;
import com.ruoyi.play.service.IWhereToGoOptionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 去哪选项Controller
 * 
 * @author ruoyi
 * @date 2024-12-19
 */
@RestController
@RequestMapping("/play/whereToGoOption")
public class WhereToGoOptionController extends BaseController
{
    @Autowired
    private IWhereToGoOptionService whereToGoOptionService;

    /**
     * 查询去哪选项列表
     */
    @PreAuthorize("@ss.hasPermi('play:whereToGoOption:list')")
    @GetMapping("/list")
    public TableDataInfo list(WhereToGoOption whereToGoOption)
    {
        startPage();
        List<WhereToGoOption> list = whereToGoOptionService.selectWhereToGoOptionList(whereToGoOption);
        return getDataTable(list);
    }

    /**
     * 根据模块ID查询选项列表
     */
    @GetMapping("/listByModule/{moduleId}")
    public AjaxResult listByModule(@PathVariable("moduleId") Long moduleId)
    {
        List<WhereToGoOption> list = whereToGoOptionService.selectWhereToGoOptionByModuleId(moduleId);
        return success(list);
    }

    /**
     * 导出去哪选项列表
     */
    @PreAuthorize("@ss.hasPermi('play:whereToGoOption:export')")
    @Log(title = "去哪选项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WhereToGoOption whereToGoOption)
    {
        List<WhereToGoOption> list = whereToGoOptionService.selectWhereToGoOptionList(whereToGoOption);
        ExcelUtil<WhereToGoOption> util = new ExcelUtil<WhereToGoOption>(WhereToGoOption.class);
        util.exportExcel(response, list, "去哪选项数据");
    }

    /**
     * 获取去哪选项详细信息
     */
    @PreAuthorize("@ss.hasPermi('play:whereToGoOption:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(whereToGoOptionService.selectWhereToGoOptionById(id));
    }

    /**
     * 新增去哪选项
     */
    @PreAuthorize("@ss.hasPermi('play:whereToGoOption:add')")
    @Log(title = "去哪选项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WhereToGoOption whereToGoOption)
    {
        return toAjax(whereToGoOptionService.insertWhereToGoOption(whereToGoOption));
    }

    /**
     * 修改去哪选项
     */
    @PreAuthorize("@ss.hasPermi('play:whereToGoOption:edit')")
    @Log(title = "去哪选项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WhereToGoOption whereToGoOption)
    {
        return toAjax(whereToGoOptionService.updateWhereToGoOption(whereToGoOption));
    }

    /**
     * 删除去哪选项
     */
    @PreAuthorize("@ss.hasPermi('play:whereToGoOption:remove')")
    @Log(title = "去哪选项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(whereToGoOptionService.deleteWhereToGoOptionByIds(ids));
    }

    /**
     * 更新选项热度值
     */
    @PostMapping("/updatePopularity/{id}")
    public AjaxResult updatePopularity(@PathVariable("id") Long id)
    {
        return toAjax(whereToGoOptionService.updateOptionPopularity(id));
    }
} 